package com.qingfeng.common.service;

//import feign.RequestInterceptor;
//import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Objects;

/**
 * @author cb
 * @Description TODO
 * @date 2023/6/7
 */
//@Slf4j
//public class FeignTokenInterceptor implements RequestInterceptor {
//    /**
//     * 这里可以实现对请求的拦截，对请求添加一些额外信息之类的
//     *
//     * @param requestTemplate
//     */
//    @Override
//    public void apply(RequestTemplate requestTemplate) {
//        final ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        if (Objects.isNull(attributes)) {
//            log.error("MyFeignRequestInterceptor is invalid!");
//            return;
//        }
//        HttpServletRequest request = attributes.getRequest();
//        Enumeration<String> headerNames = request.getHeaderNames();
//        if (Objects.nonNull(headerNames)) {
//            while (headerNames.hasMoreElements()) {
//                String name = headerNames.nextElement();
//                String value = request.getHeader(name);
//                requestTemplate.header(name, value);
//            }
//        }
//    }
//}
